package com.chenyongjing.design.pattern.memento.general;

/**
 * @Author chen
 * @Date 2022/11/23 22:13
 */
public class Test {
    public static void main(String[] args) {
        Originator originator = new Originator();
        Caretaker caretaker = new Caretaker();
        // 创建快照

        Memento memento =new Memento();
        memento.setSate("0");
        memento = originator.createMemento();
        memento.setSate("1");
        caretaker.stroeMemento(memento);
        // 创建第二次快照
        memento = originator.createMemento();
        memento.setSate("2");
        caretaker.stroeMemento(memento);

        System.out.println(caretaker.toString());
        memento.setSate("3");

        // 撤销快照
        originator.restoreMemento(caretaker.getMemento());
        System.out.println("撤销状态:"+originator.getSate());

        System.out.println(caretaker.toString());





    }
}
